<?php

    require 'database.php'; 
    $sql="select * from  comments";
    $result=$db->query($sql);
   $num=$result->num_rows;
   $postdata=$result->fetch_all(MYSQL_ASSOC);
     $page= isset($_GET['page'])?$_GET['page']:1;
   $sql='SELECT COUNT(*) AS total FROM posts';
   $res=mysql_query($sql);
   $row=mysql_fetch_assoc($res);
   $total=$row['total'];
   $size=15;
   $length=ceil($total/$size);
   $rows=findByPage($page,$size);
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>阿里百秀登录管理</title>
  <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="../assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="../assets/css/admin.css">
  <script src="../assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
    <nav class="navbar">
      <button class="btn btn-default navbar-btn fa fa-bars"></button>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="profile.html"><i class="fa fa-user"></i>个人中心</a></li>
        <li><a href="login.php"><i class="fa fa-sign-out"></i>退出</a></li>
      </ul>
    </nav>
    <div class="container-fluid">
      <div class="page-title">
        <h1>所有评论</h1>
      </div>
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong>发生XXX错误
      </div> -->
      <div class="page-action">
        <!-- show when multiple checked -->
        <div class="btn-batch" style="display: none">
          <button class="btn btn-info btn-sm">批量批准</button>
          <button class="btn btn-warning btn-sm">批量拒绝</button>
          <button class="btn btn-danger btn-sm">批量删除</button>
        </div>
        <ul class="pagination pagination-sm pull-right">
            <li><a href="?page=1">首页</a></li>
              <?php if ($page>1) 
              {
                  ?>
          <li><a href="?page=<?php echo $page-1; ?>">上一页</a></li>
          <?php } ?>
           <?php for($i=1;$i<=$length;$i++) {  ?>
            <li><a href="?page=<?php echo $i; ?>"><?php echo $i; ?></a></li>
           <?php } ?>
       
          <?php if ($page<$length) { ?>
          <li><a href="?page=<?php echo $page+1; ?>">下一页</a></li>
          <?php           
         }
         ?>  
            <li><a href="?page=<?php echo $length?>">尾页</a></li>   
        </ul>
      </div>
      <table class="table table-striped table-bordered table-hover">
        <thead>
          <tr>
            <th class="text-center" width="40"><input type="checkbox"></th>
            <th>作者</th>
            <th>评论</th>
            <th>评论在</th>
            <th>提交于</th>
            <th>状态</th>
            <th class="text-center" width="100">操作</th>
          </tr>
        </thead>
        <tbody>
        <?php foreach($rows as $key=>$val) { ?>
          <tr class="danger">
            <td class="text-center"><input type="checkbox"></td>
            <td><?php echo $val['author']; ?></td>
            <td><?php echo $val['content']; ?></td>
            <td><?php echo $val['email']; ?></td>
            <td><?php echo $val['created']; ?></td>
            <td><?php echo $val['status']; ?></td>
            <td class="text-center">
                <a href="posts.php" class="btn btn-info btn-xs">批准</a>
                <a  href="javascript:" onclick="if(confirm('确定删除吗？')) location.href='commentsdel.php?id=<?php echo $val['id']; ?>'" class="btn btn-danger btn-xs">删除</a>
            </td>
          </tr>
          
       <?php
         }
         ?>
        </tbody>
      </table>
    </div>
  </div>
<?php include 'aside.php';?>
  <script src="../assets/vendors/jquery/jquery.js"></script>
  <script src="../assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script>NProgress.done()</script>
</body>
</html>
